/**
 * @author banglong
 * @date 2016/12/22
 */
require(['bus', 'Layer', 'tools', 'indexApi'], function (bus, layer, tools, api) {

  bus.bind('accountQuery.queryAccountBalanceReport', function (event, payload) {
    api.queryAccountBalanceReport({
      className: 'MoveBillQueryManager',
      method: 'GetAccountBalanceReport',
      startTime: payload.startTime,
      endTime: payload.endTime,
      deptAccountID: payload.deptAccountID,
      goodsBookID: payload.goodsBookID
    }).then(function (jsonResult) {
      if (jsonResult.issuccess !== 0) {
        Promise.reject('获取信息失败');
        return
      }
      if (payload.callback) {
        payload.callback(JSON.parse(jsonResult.result))
      }
    })['catch'](function (ex) {
      if (payload.error) {
        payload.error()
      }
      tools.alterError(ex)
    })
  });

  // 年度查询
  bus.bind('accountQuery.getAccountInformation', function (event, payload) {
    api.queryAccountBalanceReport({
      className: 'ChargeBillManager',
      method: 'GetAccountInformation',
      deptAccountID: payload.deptAccountID,
      year: payload.year
    }).then(function (jsonResult) {
      if (jsonResult.issuccess !== 0) {
        Promise.reject('获取信息失败');
        return
      }
      if (payload.callback) {
        payload.callback(JSON.parse(jsonResult.result))
      }
    })['catch'](function (ex) {
      if (payload.error) {
        payload.error()
      }
      tools.alterError(ex)
    })
  });
});